#include <stdio.h>
#include <string.h>
#include "list.h"

typedef int BOOL;

union value
{
    BOOL bl;
    int in;
    float fl;
};

struct data
{
    int key;
    int type;
    union value val;
    struct list_head list;
};

int main(int argc, char **argv)
{
    struct data head;
    INIT_LIST_HEAD(&head.list);

    struct data da1;
    da1.key = 1;
    da1.type = 2;
    da1.val.bl = 10;

    struct data da2;
    da2.key = 2;
    da2.type = 1;
    da2.val.in = 0;

    struct data da3;
    da3.key = 3;
    da3.type = 3;
    da3.val.fl = 22.5;

    list_add(&da1.list, &head.list);
    list_add(&da2.list, &head.list);
    list_add(&da3.list, &head.list);

    struct list_head *pos;
    struct data *tmp;

    list_for_each(pos,&head.list)
    {
        tmp = list_entry(pos,struct data, list);
        if(tmp->type == 2)
        {
            printf("%d %d %d\n",tmp->key,tmp->type,tmp->val.bl);
        }
        else if(tmp->type == 1)
        {
            printf("%d %d %d\n",tmp->key,tmp->type,tmp->val.in);
        }
        else if(tmp->type == 3)
        {
            printf("%d %d %f\n",tmp->key,tmp->type,tmp->val.fl);
        }
    }
}
